import store from "@/store/";
import { Notification } from "element-ui";

/**
 * 当前环境下用户的权限
 *
 * @return {Array}
 */
export function currentUserPerm() {
  const rules = store.state.permission.rules;
  const envId = store.state.env.id;
  if (envId === -1) Notification.warning("请点击右上角的图标选择环境.")

  for (let i = 0; i < rules.length; i++) {
    if (rules[i].envId === envId) return rules[i].permissionSet;
  }
  return []
}

export const ALL_PERMISSIONS_LIST = {
	InterfaceManage: {
		Select: "auto_test_interface_manager_select",
		Edit: "auto_test_interface_manager_edit",
		Add: "auto_test_interface_manager_add",
		Delete: "auto_test_interface_manager_delete",
		Debug: "auto_test_interface_manager_debug",
		Import: "auto_test_interface_manager_import",
	},

	InterfaceCategory: {
		Select: "auto_test_interface_category_select",
		Add: "auto_test_interface_category_add",
		Edit: "auto_test_interface_category_edit",
		Delete: "auto_test_interface_category_delete",
	},

	TestCase: {
		Select: "auto_test_case_select",
		Add: "auto_test_case_add",
		Edit: "auto_test_case_edit",
		Delete: "auto_test_case_delete",
	},

	TaskProxy: {
		Select: "auto_test_task_proxy_select",
		Add: "auto_test_task_proxy_add",
		Edit: "auto_test_task_proxy_edit",
		Delete: "auto_test_task_proxy_delete",
		Test: "auto_test_task_proxy_test",
		Start: "auto_test_task_proxy_start",
		Stop: "auto_test_task_proxy_stop"
	},

	TaskSchedule: {
		Select: "auto_test_task_schedule_select",
		Log: "auto_test_task_schedule_log",
		Delete: "auto_test_task_schedule_delete",
	},

	TaskResult: {
		Select: "auto_test_task_result_select",
		Detail: "auto_test_task_result_detail",
		Delete: "auto_test_task_result_delete",
	},

	Executor: {
		Select: "auto_test_executor_select",
		Start: "auto_test_executor_start",
		Stop: "auto_test_executor_stop",
		Delete: "auto_test_executor_delete",
	},

	Defect: {
		Select: "auto_test_defect_select",
		Detail: "auto_test_defect_detail",
		Edit: "auto_test_defect_edit",
		Delete: "auto_test_defect_delete",
	}
};

//# 接口管理
//auto_test_interface_manager_select # 查看
//auto_test_interface_manager_add # 添加
//auto_test_interface_manager_edit # 编辑
//auto_test_interface_manager_delete # 删除
//auto_test_interface_manager_debug # 调试
//auto_test_interface_manager_import # 导入

//# 接口分类
//auto_test_interface_category_select # 查看
//auto_test_interface_category_add # 添加
//auto_test_interface_category_edit # 编辑
//auto_test_interface_category_delete # 删除

//# 用例
//auto_test_case_select # 查看
//auto_test_case_add # 添加
//auto_test_case_edit # 编辑
//auto_test_case_delete # 删除

//# 任务管理
//auto_test_task_proxy_test # 执行测试
//auto_test_task_proxy_start # 启动
//auto_test_task_proxy_stop # 暂停
//auto_test_task_proxy_select # 查看
//auto_test_task_proxy_add # 添加
//auto_test_task_proxy_edit # 编辑
//auto_test_task_proxy_delete # 删除

//# 任务调度
//auto_test_task_schedule_select # 查看
//auto_test_task_schedule_log # 日志
//auto_test_task_schedule_delete # 删除

//# 任务结果
//auto_test_task_result_select # 查看
//auto_test_task_result_detail # 详情
//auto_test_task_result_delete # 删除

//# 执行机
//auto_test_executor_stop # 隔离
//auto_test_executor_start # 启动
//auto_test_executor_delete # 删除

//# 缺陷
//auto_test_defect_detail # 详情
//auto_test_defect_edit # 编辑
//auto_test_defect_delete # 删除
